<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String code = request.getParameter("code");
	String path = request.getContextPath();
	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>授权申请</title>
<!--框架必需start-->
<jsp:include page="/manage/accordion/framework_inc.jsp" flush="false" />
<!--框架必需end-->

<script type="text/javascript">
	var code = '<%=code%>';
	var redirect_uri= 'http://localhost:8080/mvn/token_manager/';
	var appKey = '1298627';
	var client_secret = '0XEfZcBWt5';
	
		
	/**
	 *	添加产品分组
	 */
	function getToken(){
		
// 		alert(code);
		if(code != null && code != "null"){
			var url = "https://gw.api.alibaba.com/openapi/http/1/system.oauth2/getToken/";
			url += appKey + "?";
			url += 'grant_type=authorization_code&need_refresh_token=true';
			url += '&client_id='+appKey;
			url += '&client_secret='+client_secret;
			url += '&redirect_uri='+redirect_uri;
			url += '&code='+code;
// 			alert(url);
			$.ajax({
			  type: 'POST',
			  url: url,
			  data: null,
			  success: function(result){
// 				  JSON.encode(result);
				  alert(result);
					
				  },
			  dataType: 'json',
			  headers: {
		            'Content-Type' : 'application/x-www-form-urlencoded'
		        }
			});

		}else{
			var modelObj = $("#groupForm").formToArray();
			var param = "";
			var url = "<%=path%>/token_manager";
			for(var i = 0 ;i < modelObj.length ; i++){
// 				param += modelObj[i].name + "=" +  modelObj[i].value + "&";
				url +="/" + modelObj[i].value;
				
			}
// 			alert(url);
// 			alert(param	);
			$.get(url, function(data) {
				location.href = data;
				});
			
		}
		
	}
	getToken();
</script>
</head>
<body>

	<div class="box1" panelWidth="650">
	<fieldset> 
		<legend>产品分组</legend> 
			<form id="groupForm" name="groupForm" method="post" action="">
				<table class="tableStyle" formMode="transparent" footer="normal">
					<tr>
						<td width="15%">appkey：</td>
						<td width="15%"><input name="appkey" id="appkey" value="1298627" type="text"/></td>
						<td width="15%">appSecret：</td>
						<td><input name="appSecret" id="appSecret" value="0XEfZcBWt5" type="text"/></td>
						<td width="15%">state：</td>
						<td><input name="state" id="state" value="state" type="text"/></td>
					</tr>
				</table>
			</form>
	</fieldset> 
	<div class="height_5"></div>
	<div class="padding_top10">
		<table class="tableStyle" formMode="transparent">
			<tr>
				<td colspan="4">
					<input type="button" onclick="getToken();" value="提交"/>
					<input type="reset" value="重置"/>
				</td>
			</tr>
		</table>
	</div> 
	</div>

</div>
 
</body>
</html>